var myCirclePlayer;
var currItemNumber;
var sermonList = [
	"../AUDIO/2013/SUNDAY%20SCHOOL/02032013sundayschool.mp3",
	"../AUDIO/2013/SUNDAY%20SCHOOL/02102013sundayschool.mp3",
	"../AUDIO/2013/SUNDAY%20SCHOOL/02172013sundayschool.mp3",
	"../AUDIO/2013/SUNDAY%20SCHOOL/02242013sundayschool.mp3",
	"../AUDIO/2013/SUNDAY%20SCHOOL/03032013sundayschool.mp3",
	"../AUDIO/2013/SUNDAY%20SCHOOL/03102013sundayschool.mp3",
	"../AUDIO/2013/SUNDAY%20SCHOOL/03172013sundayschool.mp3",
	"../AUDIO/2013/SUNDAY%20SCHOOL/03242013sundayschool.mp3",
	"../AUDIO/2013/SUNDAY%20SCHOOL/03312013sundayschool.mp3",
	"../AUDIO/2013/SUNDAY%20SCHOOL/04212013sundayschool.mp3",
	"../AUDIO/2013/SUNDAY%20SCHOOL/04282013sundayschool.mp3",
	"../AUDIO/2013/SUNDAY%20SCHOOL/05052013sundayschool.mp3",
	"../AUDIO/2013/SUNDAY%20SCHOOL/05122013sundayschool.mp3",
	"../AUDIO/2013/SUNDAY%20SCHOOL/05192013sundayschool.mp3",
	"../AUDIO/2013/SUNDAY%20SCHOOL/05262013sundayschool.mp3",
	"../AUDIO/2013/SUNDAY%20SCHOOL/06022013sundayschool.mp3",
	"../AUDIO/2013/SUNDAY%20SCHOOL/06092013sundayschool.mp3",
	"../AUDIO/2013/SUNDAY%20SCHOOL/06162013sundayschool.mp3",
	"../AUDIO/2013/SUNDAY%20SCHOOL/06232013sundayschool.mp3",
	"../AUDIO/2013/SUNDAY%20SCHOOL/06302013sundayschool.mp3",
	"../AUDIO/2013/SUNDAY%20SCHOOL/07072013sundayschool.mp3",
	"../AUDIO/2013/SUNDAY%20SCHOOL/07142013sundayschool.mp3",
	"../AUDIO/2013/SUNDAY%20SCHOOL/07212013sundayschool.mp3",
	"../AUDIO/2013/SUNDAY%20SCHOOL/07282013sundayschool.mp3",
	"../AUDIO/2013/SUNDAY%20SCHOOL/08042013sundayschool.mp3",
	"../AUDIO/2013/SUNDAY%20SCHOOL/08112013sundayschool.mp3",
	"../AUDIO/2013/SUNDAY%20SCHOOL/08182013sundayschool.mp3",
	"../AUDIO/2013/SUNDAY%20SCHOOL/08252013sundayschool.mp3",
	"../AUDIO/2013/SUNDAY%20SCHOOL/09012013sundayschool.mp3",
	"../AUDIO/2013/SUNDAY%20SCHOOL/09152013sundayschool.mp3",
	"../AUDIO/2013/SUNDAY%20SCHOOL/09222013sundayschool.mp3",
	"../AUDIO/2013/SUNDAY%20SCHOOL/09292013sundayschool.mp3",
	"../AUDIO/2013/SUNDAY%20SCHOOL/10062013sundayschool.mp3",
	"../AUDIO/2013/SUNDAY%20SCHOOL/10132013sundayschool.mp3",
	"../AUDIO/2013/SUNDAY%20SCHOOL/10202013sundayschool.mp3",
	"../AUDIO/2013/SUNDAY%20SCHOOL/10272013sundayschool.mp3",
	"../AUDIO/2013/SUNDAY%20SCHOOL/11032013sundayschool.mp3",
	"../AUDIO/2013/SUNDAY%20SCHOOL/11102013sundayschool.mp3",
	"../AUDIO/2013/SUNDAY%20SCHOOL/11172013sundayschool.mp3",
	"../AUDIO/2013/SUNDAY%20SCHOOL/12082013sundayschool.mp3",
	"../AUDIO/2013/SUNDAY%20SCHOOL/12222013sundayschool.mp3",
	"../AUDIO/2013/SUNDAY%20SCHOOL/12292013sundayschool.mp3",
	"../AUDIO/2014/SUNDAY%20SCHOOL/01052014sundayschool.mp3",
	"../AUDIO/2014/SUNDAY%20SCHOOL/01122014sundayschool.mp3",
	"../AUDIO/2014/SUNDAY%20SCHOOL/01192014sundayschool.mp3",
	"../AUDIO/2014/SUNDAY%20SCHOOL/01262014sundayschool.mp3",
	"../AUDIO/2014/SUNDAY%20SCHOOL/02022014sundayschool.mp3",
	"../AUDIO/2014/SUNDAY%20SCHOOL/02092014sundayschool.mp3",
	"../AUDIO/2014/SUNDAY%20SCHOOL/02162014sundayschool.mp3",
	"../AUDIO/2014/SUNDAY%20SCHOOL/02232014sundayschool.mp3",
	"../AUDIO/2014/SUNDAY%20SCHOOL/03022014sundayschool.mp3",
	"../AUDIO/2014/SUNDAY%20SCHOOL/03092014sundayschool.mp3",
	"../AUDIO/2014/SUNDAY%20SCHOOL/03162014sundayschool.mp3",
	"../AUDIO/2014/SUNDAY%20SCHOOL/03232014sundayschool.mp3",
	"../AUDIO/2014/SUNDAY%20SCHOOL/03302014sundayschool.mp3",
	"../AUDIO/2014/SUNDAY%20SCHOOL/04062014sundayschool.mp3",
	"../AUDIO/2014/SUNDAY%20SCHOOL/04132014sundayschool.mp3",
	"../AUDIO/2014/SUNDAY%20SCHOOL/04272014sundayschool.mp3",
	"../AUDIO/2014/SUNDAY%20SCHOOL/05042014sundayschool.mp3",
	"../AUDIO/2014/SUNDAY%20SCHOOL/05112014sundayschool.mp3",
	"../AUDIO/2014/SUNDAY%20SCHOOL/05182014sundayschool.mp3",
	"../AUDIO/2014/SUNDAY%20SCHOOL/05252014sundayschool.mp3",
	"../AUDIO/2014/SUNDAY%20SCHOOL/06082014sundayschool.mp3",
	"../AUDIO/2014/SUNDAY%20SCHOOL/06152014sundayschool.mp3",
	"../AUDIO/2014/SUNDAY%20SCHOOL/06292014sundayschool.mp3",
	"../AUDIO/2014/SUNDAY%20SCHOOL/07062014sundayschool.mp3",
	"../AUDIO/2014/SUNDAY%20SCHOOL/07132014sundayschool.mp3",
	"../AUDIO/2014/SUNDAY%20SCHOOL/07202014sundayschool.mp3",
	"../AUDIO/2014/SUNDAY%20SCHOOL/07272014sundayschool.mp3",
	"../AUDIO/2014/SUNDAY%20SCHOOL/08032014sundayschool.mp3",
	"../AUDIO/2014/SUNDAY%20SCHOOL/08102014sundayschool.mp3",
	"../AUDIO/2014/SUNDAY%20SCHOOL/08172014sundayschool.mp3",
	"../AUDIO/2014/SUNDAY%20SCHOOL/08242014sundayschool.mp3",
    "../AUDIO/2014/SUNDAY%20SCHOOL/09072014sundayschool.mp3",
    "../AUDIO/2014/SUNDAY%20SCHOOL/09212014sundayschool.mp3",
    "../AUDIO/2014/SUNDAY%20SCHOOL/09282014sundayschool.mp3",
    "../AUDIO/2014/SUNDAY%20SCHOOL/10052014sundayschool.mp3",
    "../AUDIO/2014/SUNDAY%20SCHOOL/10122014sundayschool.mp3",
    "../AUDIO/2014/SUNDAY%20SCHOOL/10192014sundayschool.mp3",
    "../AUDIO/2014/SUNDAY%20SCHOOL/10262014sundayschool.mp3",
    "../AUDIO/2014/SUNDAY%20SCHOOL/11022014sundayschool.mp3",
    "../AUDIO/2014/SUNDAY%20SCHOOL/11092014sundayschool.mp3",
    "../AUDIO/2014/SUNDAY%20SCHOOL/11162014sundayschool.mp3",
    "../AUDIO/2014/SUNDAY%20SCHOOL/11232014sundayschool.mp3",
    "../AUDIO/2014/SUNDAY%20SCHOOL/11302014sundayschool.mp3",
    "../AUDIO/2014/SUNDAY%20SCHOOL/12072014sundayschool.mp3",
    "../AUDIO/2014/SUNDAY%20SCHOOL/12142014sundayschool.mp3",
    "../AUDIO/2014/SUNDAY%20SCHOOL/12212014sundayschool.mp3",
    "../AUDIO/2014/SUNDAY%20SCHOOL/12282014sundayschool.mp3",
    "../AUDIO/2015/SUNDAY%20SCHOOL/01042015sundayschool.mp3",
    "../AUDIO/2015/SUNDAY%20SCHOOL/01112015sundayschool.mp3",
    "../AUDIO/2015/SUNDAY%20SCHOOL/01182015sundayschool.mp3",
    "../AUDIO/2015/SUNDAY%20SCHOOL/01252015sundayschool.mp3"
];

function selectItem(item) {
    if (0 <= currItemNumber && currItemNumber < sermonList.length) {
    	var currItem = document.getElementById("player-item-" + currItemNumber.toString());
        removeClass(currItem, 'bold');
        removeClass(currItem, 'colorPrimary-5');
        addClass(currItem, 'colorSecondary-a-2');
    }
    addClass(item, 'bold');
    addClass(item, 'colorPrimary-5');
    removeClass(item, 'colorSecondary-a-2');
    currItemNumber = parseInt(item.id.substr(item.id.lastIndexOf("-") + 1));
    myCirclePlayer.setMedia({
    	mp3: sermonList[currItemNumber]
    });
}

function playItem(item) {
    selectItem(item);
	myCirclePlayer.play();
}

function playNextItem() {
    var nextItemNumber = currItemNumber + 1;
    if (nextItemNumber < sermonList.length) {
        playItem(document.getElementById("player-item-" + nextItemNumber.toString()));
    }
}

$(document).ready(function(){
	myCirclePlayer = new CirclePlayer("#jquery_jplayer_1",
	{
	}, {
		supplied: "mp3",
		cssSelectorAncestor: "#cp_container_1",
		swfPath: "../Content/Javascript/jplayer/Jplayer.swf",
		wmode: "window",
		keyEnabled: true
	});

    $("#jquery_jplayer_1").bind($.jPlayer.event.ended, function (event) {
        playNextItem();
    });
    
    for(var i = 0; i < sermonList.length; ++i){
		addClass(document.getElementById("player-item-" + i.toString()), 'colorSecondary-a-2');
	}

    selectItem(document.getElementById("player-item-" + (sermonList.length - 1).toString()));
});
